package com.car.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipOutput {
	
	public static String getZipOut(String strZipName,File[] file1){
		try {
			byte[] buffer = new byte[1024];
			
			ZipOutputStream out = new ZipOutputStream(new FileOutputStream("/mydata/uploadtea/pack/"+strZipName));
			
			for(int i=0;i<file1.length;i++) {
				if(file1[i]!=null && !file1[i].equals("") && !file1[i].equals("/mydata/uploadtea/pack/")){
					FileInputStream fis;
					
					fis = new FileInputStream(file1[i]);
					
					out.putNextEntry(new ZipEntry(file1[i].getName()));
					
					int len;
					
					while((len = fis.read(buffer))>0) {
					
						out.write(buffer,0,len);
					
					}
					
					out.closeEntry();
					fis.close();
				}
			}
			out.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("成功！");
		return strZipName;
	}

	public static void main(String[] args) throws Exception {

		byte[] buffer = new byte[1024];
		
		String strZipName = "Demo.zip";
		
		ZipOutputStream out = new ZipOutputStream(new FileOutputStream("d:"+strZipName));
		
		File[] file1 = {new File("e:1.mp3"),new File("e:2.mp3")};
		
		for(int i=0;i<file1.length;i++) {
			
			if(file1[i]!=null && !file1[i].equals("")){
				FileInputStream fis = new FileInputStream(file1[i]);
				
				out.putNextEntry(new ZipEntry(file1[i].getName()));
				
				int len;
				
				while((len = fis.read(buffer))>0) {
				
					out.write(buffer,0,len);
				
				}
				
				out.closeEntry();
				fis.close();
			}
			
		}
		out.close();
		
	}
}
